
private alias object.value0 : saveram.selection
private alias object.value1 : cursor.leftcount
private alias object.value2 : cursor.rightcount
private alias object.value3 : cursor.upcount
private alias object.value4 : cursor.downcount
private alias object.value5 : cursor.Acount
private alias object.value6 : cursor.Bcount

reserve function buttonhold

function buttonhold	
	if inputDown.up == 1
		cursor.upcount++
		if cursor.upcount >= 20
			cursor.upcount = 12
			inputPress.up = 1
		end if
	else
		cursor.upcount = 0
	end if
		
	if inputDown.down == 1
		cursor.downcount++
		if cursor.downcount >= 20
			cursor.downcount = 12
			inputPress.down = 1
		end if
	else
		cursor.downcount = 0
	end if

	if inputDown.left == 1
		cursor.leftcount++
		if cursor.leftcount >= 20
			cursor.leftcount = 12
			inputPress.left = 1
		end if
	else
		cursor.leftcount = 0
	end if
	
	if inputDown.right == 1
		cursor.rightcount++
		if cursor.rightcount >= 20
			cursor.rightcount = 12
			inputPress.right = 1
		end if
	else
		cursor.rightcount = 0
	end if
	
	if inputDown.buttonA == 1
		cursor.Acount++
		if cursor.Acount >= 20
			cursor.Acount = 12
			inputPress.buttonA = 1
		end if
	else
		cursor.Acount = 0
	end if
	
	if inputDown.buttonB == 1
		cursor.Bcount++
		if cursor.Bcount >= 20
			cursor.Bcount = 12
			inputPress.buttonB = 1
		end if
	else
		cursor.Bcount = 0
	end if
end function

event ObjectMain
	StopMusic()
	CallFunction(buttonhold)
	
	if inputPress.up == 1
		saveram.selection--
	else
		if inputPress.down == 1
			saveram.selection++
		else
			if inputPress.buttonA == 1
				saveram.selection += 100
			else
				if inputPress.buttonB == 1
					saveram.selection -= 100
				end if
			end if
		end if
	end if
	
	if saveram.selection < 0
		saveram.selection = 0
	else
		if saveram.selection > 8191
			saveram.selection = 8191
		end if
	end if
	arrayPos0 = saveram.selection
	
	if inputPress.left == 1
		saveRAM[arrayPos0]--
	else
		if inputPress.right == 1
			saveRAM[arrayPos0]++
		else
			if inputPress.buttonC == 1
				saveRAM[arrayPos0] = 0
			else
				if inputPress.start == 1
					StopMusic()
					WriteSaveRAM()
					stage.activeList = PRESENTATION_STAGE
					stage.listPos = 0
					LoadStage()
				end if
			end if
		end if
	end if
end event

event ObjectDraw
	DrawRect(0, 0, screen.xsize, screen.ysize, 0, 128, 128, 255)
	
	arrayPos1 = saveram.selection
	arrayPos1 -= 8
	arrayPos2 = saveram.selection
	arrayPos2 += 8
	
	if arrayPos1 < 0
		arrayPos1 = 0
		arrayPos2 = 16
	else
		if arrayPos2 > 8192
			arrayPos1 = 8176
			arrayPos2 = 8192
		end if
	end if
	
	temp0 = 4
	temp1 = screen.xsize
	temp1 -= 18
	while arrayPos1 < arrayPos2
		if arrayPos1 == saveram.selection
			temp0--
			DrawRect(0, temp0, screen.xsize, 13, 0, 0, 224, 255)
			DrawSpriteScreenXY(11, 0, temp0)
			DrawSpriteScreenXY(12, screen.xsize, temp0)
			temp0++
		end if
		DrawNumbers(0, 33, temp0, arrayPos1, 4, 8, 1)
		if saveRAM[arrayPos1] < 0
			temp2 = saveRAM[arrayPos1]
			FlipSign(temp2)
			DrawNumbers(0, temp1, temp0, temp2, 8, 8, 0)
			temp3 = temp1
			while temp2 > 0
				temp3 -= 8
				temp2 /= 10
			loop
			DrawSpriteScreenXY(10, temp3, temp0)
		else		
			DrawNumbers(0, temp1, temp0, saveRAM[arrayPos1], 8, 8, 0)
		end if		
		temp0 += 12
		DrawRect(0, temp0, screen.xsize, 1, 224, 224, 224, 255)
		temp0 += 2
		arrayPos1++		
	loop
end event

event ObjectStartup
	LoadSpriteSheet("Global/HUD.gif")
	SpriteFrame(0, 0, 6, 8, 110, 19) 	// 24 - Life icon number 0
	SpriteFrame(0, 0, 6, 8, 117, 19)  	// 25 - Life icon number 1
	SpriteFrame(0, 0, 6, 8, 124, 19)  	// 26 - Life icon number 2
	SpriteFrame(0, 0, 6, 8, 131, 19)  	// 27 - Life icon number 3
	SpriteFrame(0, 0, 6, 8, 138, 19)  	// 28 - Life icon number 4
	SpriteFrame(0, 0, 6, 8, 145, 19)  	// 29 - Life icon number 5
	SpriteFrame(0, 0, 6, 8, 152, 19)  	// 30 - Life icon number 6
	SpriteFrame(0, 0, 6, 8, 159, 19)  	// 31 - Life icon number 7
	SpriteFrame(0, 0, 6, 8, 166, 19)  	// 32 - Life icon number 8
	SpriteFrame(0, 0, 6, 8, 173, 19)  	// 33 - Life icon number 9
	SpriteFrame(-16, 0, 8, 8, 127, 64) 	// 34 - Debug minus icon
	SpriteFrame(8, 0, 8, 8, 136, 64) 	// 35 - Debug plus icon
	SpriteFrame(0, 0, 8, 8, 25, 98) 	// 36 - Debug red "X"
	SpriteFrame(0, 0, 8, 8, 34, 98) 	// 37 - Debug red "Y"
end event

	
end event
